package com.ijustyce.market.ItemAndAdapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.ijustyce.market.R;

import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

    private List<goods> mFruitList;

    public static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView Image;
        TextView Name;
        TextView Price;
        TextView trans;
        TextView Location;
        public ViewHolder(View view) {
            super(view);
            Image = (ImageView) view.findViewById(R.id.iv);
            Name = (TextView) view.findViewById(R.id.tv);
            Price=(TextView) view.findViewById(R.id.PriceNum);
            trans=(TextView) view.findViewById(R.id.transNum);
            Location=(TextView) view.findViewById(R.id.Location);
        }

    }

    public MyAdapter(List<goods> fruitList) {
        mFruitList = fruitList;
    }

    @Override

    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        goods good = mFruitList.get(position);
        holder.Image.setImageResource(good.getImageId());
        holder.Name.setText(good.getName());
        holder.Price.setText(good.getPrince());
        holder.trans.setText(good.gettransactionNumber());
        holder.Location.setText(good.getLocation());

    }

    @Override
    public int getItemCount() {
        return mFruitList.size();
    }
}
